package com.xxq.gulimall.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.xxq.gulimall.product.entity.BrandEntity;
import com.xxq.gulimall.product.entity.CategoryEntity;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xxq.common.utils.PageUtils;
import com.xxq.common.utils.Query;

import com.xxq.gulimall.product.dao.CategoryBrandRelationDao;
import com.xxq.gulimall.product.entity.CategoryBrandRelationEntity;
import com.xxq.gulimall.product.service.CategoryBrandRelationService;

import javax.annotation.Resource;


@Service("categoryBrandRelationService")
public class CategoryBrandRelationServiceImpl extends ServiceImpl<CategoryBrandRelationDao, CategoryBrandRelationEntity> implements CategoryBrandRelationService {
    @Resource
    private CategoryBrandRelationDao relationDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<CategoryBrandRelationEntity> page = this.page(
                new Query<CategoryBrandRelationEntity>().getPage(params),
                new QueryWrapper<CategoryBrandRelationEntity>()
        );

        return new PageUtils(page);
    }

    @Override // TODO 暂无
    public void updateBrandName(BrandEntity brand) {
        UpdateWrapper<CategoryBrandRelationEntity> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("brand_id", brand.getBrandId());
        updateWrapper.set("brand_name", brand.getName());
        this.update(updateWrapper);
    }

    @Override // TODO 暂无
    public void updateCatelogName(CategoryEntity category) {
        UpdateWrapper<CategoryBrandRelationEntity> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("catelog_id", category.getCatId());
        updateWrapper.set("catelog_name", category.getName());
        this.update(updateWrapper);
    }

    @Override // TODO 多表查询
    public List<CategoryBrandRelationEntity> queryBrands(Long catId) {
        return relationDao.queryBrands(catId);
    }

    @Override // TODO 多表查询
    public List<CategoryBrandRelationEntity> queryCategory(Long brandId) {
        return relationDao.queryCategory(brandId);
    }

    @Override // TODO 多表查询
    public void saveRelation(CategoryBrandRelationEntity entity) {
        CategoryBrandRelationEntity relationEntity= relationDao.queryName(entity.getBrandId(), entity.getCatelogId());
        relationEntity.setBrandId(entity.getBrandId());
        relationEntity.setCatelogId(entity.getCatelogId());
        baseMapper.insert(relationEntity);
    }

}